﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace PhoneApp1
{
    public partial class Page2 : PhoneApplicationPage
    {
        Algorithem algo;
        private AppSettings settings = new AppSettings();
        public Page2()
        {
            InitializeComponent();
            algo = Algorithem.GetInstance();
            
            
            algo.points = settings.GetValueOrDefault<double>(AppSettings.pointsSettingKeyName, AppSettings.pointsSettingDefault);
            algo.PensionPercentage = settings.GetValueOrDefault<double>(AppSettings.pensionPercentageSettingKeyName, AppSettings.pensionPercentageSettingDefault)*0.01;
            algo.kerenPercantage = settings.GetValueOrDefault<double>(AppSettings.kerenHishtalmutPercentSettingKeyName, AppSettings.kerenHishtalmutPercentSettingDefault)*0.01;
            algo.salaryWithoutPension  = settings.GetValueOrDefault<double>(AppSettings.salaryWithoutPensionSettingKeyName, AppSettings.salaryWithoutPensionSettingDefault);
            algo.driving = settings.GetValueOrDefault<double>(AppSettings.drivingRefundSettingKeyName, AppSettings.drivingRefundSettingDefault);
            algo.setHybrid(settings.GetValueOrDefault<bool>(AppSettings.isHybridSettingKeyName, AppSettings.isHybridSettingDefault));
            algo.setLeasing(settings.GetValueOrDefault<bool>(AppSettings.isLeasingSettingKeyName, AppSettings.isLeasingSettingDefault));
            algo.setCarPrice(settings.GetValueOrDefault<double>(AppSettings.carPriceSettingKeyName, AppSettings.carsPriceSettingDefault));
            algo.setMonthlyPaymentForCar(settings.GetValueOrDefault<double>(AppSettings.companyPaymentForCarKeyName, AppSettings.companyPaymentForLeasingSettingDefault));
            netoButton.Text = Math.Round(algo.Calculate()).ToString();
            pensionText.Text = Math.Round(algo.GetSocialAlocation()).ToString();
            taxesText.Text = Math.Round(algo.GetTaxes()).ToString();
            if (algo.isLeasing())
            {
                leasing.Visibility = System.Windows.Visibility.Visible;
            }
            
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Button button = (sender as Button);
            if (onlyHishtalmut.Visibility == System.Windows.Visibility.Collapsed)
            {
                button.Content = "סגור פירוט";
                onlyPension.Text = algo.GetPenstionPayment().ToString() +" :"+ "לקרן פנסיה";
                onlyHishtalmut.Text = algo.GetKerenHishtalmut().ToString()+" :" +"לקרן השתלמות";
                onlyHishtalmut.Visibility = System.Windows.Visibility.Visible;
                onlyPension.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                button.Content = "פתח פירוט";
                onlyHishtalmut.Visibility = System.Windows.Visibility.Collapsed;
                onlyPension.Visibility = System.Windows.Visibility.Collapsed;
            }
        }

        private void taxesButton_Click_1(object sender, RoutedEventArgs e)
        {
            Button button = (sender as Button);
            if (incomeTax.Visibility == System.Windows.Visibility.Collapsed)
            {
                button.Content = "סגור פירוט";
                incomeTax.Text = algo.GetIncomeTax().ToString() + " :" + "למס הכנסה";
                healthTax.Text = algo.GetHealthTax().ToString() + " :" + "למס בריאות";
                socialSecurityText.Text = algo.getsocialSecurity().ToString() + " :" + "לביטוח לאומי";
                incomeTax.Visibility = System.Windows.Visibility.Visible;
                healthTax.Visibility = System.Windows.Visibility.Visible;
                socialSecurityText.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                button.Content = "פתח פירוט";
                incomeTax.Visibility = System.Windows.Visibility.Collapsed;
                healthTax.Visibility = System.Windows.Visibility.Collapsed;
                socialSecurityText.Visibility = System.Windows.Visibility.Collapsed;
            }
        }
    }
}